package com.example.weather.girl

import com.example.library_base.base.BaseRepository
import com.example.weather.imp.Service
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import retrofit2.HttpException
import javax.inject.Inject

@ViewModelScoped
class GirlRepository @Inject constructor()
    : BaseRepository<Service>(Service::class.java) {

    suspend fun getGirlList(map: Map<String, Any>) = withContext(Dispatchers.IO) {
        try {
            val result = service.getGirlList(map)
            result.data
        }catch (e: HttpException){
            println("网络请求错误")
            println(e.message)
            println(e.code())
            println(e.response())
        }
    }

    suspend fun executionSequence1(map: Map<String, Any>) = withContext(Dispatchers.IO) {
        println("网络请求executionSequence1")
        try {
            "顺序1"
        }catch (e: HttpException){
            println("网络请求错误")
            println(e.message)
            println(e.code())
            println(e.response())
        }
    }

    suspend fun executionSequence2(map: Map<String, Any>) = withContext(Dispatchers.IO) {
        println("网络请求executionSequence2")
        try {
            Thread.sleep(2000)
            "顺序2"
        }catch (e: HttpException){
            println("网络请求错误")
            println(e.message)
            println(e.code())
            println(e.response())
        }
    }

    suspend fun executionSequence3(map: Map<String, Any>) = withContext(Dispatchers.IO) {
        println("网络请求executionSequence3")
        try {
            "顺序3"
        }catch (e: HttpException){
            println("网络请求错误")
            println(e.message)
            println(e.code())
            println(e.response())
        }
    }
}